<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<link rel="stylesheet" type="text/css" media="screen"
	href="${ctx}/static/jqgrid/css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen"
	href="${ctx}/static/jqgrid/css/jquery-ui-1.8.21.custom.css" />
<script src="${ctx}/static/js/jquery.min.js"
	type="text/javascript"></script>
<SCRIPT type="text/javascript" src="${ctx }/static/js/jquery-ui-1.8.21.custom.min.js"></SCRIPT>


<script src="${ctx}/static/jqgrid/js/i18n/grid.locale-cn.js"
	type="text/javascript"></script>
<script src="${ctx}/static/jqgrid/js/jquery.jqGrid.min.js"
	type="text/javascript"></script>
	
<!-- jalert -->
<link rel="stylesheet" type="text/css" media="screen"
	href="${ctx}/static/jalert/jquery.alerts.css" />
<script src="${ctx}/static/jalert/jquery.ui.draggable.js"
	type="text/javascript"></script>
<script src="${ctx}/static/jalert/jquery.alerts.js"
	type="text/javascript"></script>
<style type="text/css">
	body{
		background:#EEF2FB
	}
</style>	
<script type="text/javascript">

	
	jQuery(document).ready(function() {
		jQuery("#list").jqGrid({
			url : '${ctx}/admin/confirmMoney/outList?state=to_apply',
			datatype : 'json',
			mtype : 'GET',
			colNames : [ '', '用户名', '申请款额','账户现有余额','申请时间','申请状态','更新时间' ],
			colModel : [ {
				name : 'id',
				index : 'id',
				align : 'center',
				hidden:true,
				editable : false
			}, {
				name : 'uname',
				index : 'uname',
				align : 'center',
				editable : true
			}, {
				name : 'money',
				index : 'money',
				align : 'center',
				editable : true
			}, {
				name : 'money_rest',
				index : 'money_rest',
				align : 'center',
				editable : true
			}, {
				name : 'apply_time',
				index : 'apply_time',
				align : 'center',
				editable : true
			}, {
				name : 'state',
				index : 'state',
				align : 'center',
				editable : true
			}, {
				name : 'update_time',
				index : 'update_time',
				align : 'center',
				editable : true
			} ],
			jsonReader: {
				repeatitems : false
			},
			pager : '#pager',
			rowNum : 20,
			rowList : [ 10, 20, 30 ],
			sortname : 'id',
			sortorder : 'desc',
			viewrecords : true,
			reloadAfterSubmit:true,
			width:900,
			height:405,
			multiselect: true,
			
		    editurl:'${ctx}/admin/confirmMoney/edit',
			caption : '产品列表'
		});
		
		jQuery("#list").jqGrid('navGrid', '#pager',{
			add:true,
			edit:false,
			del:true,
			edittext:"修改", searchtext:"搜索", addtext:"添加", deltext:"删除"
		},{
			width:600,
			closeAfterEdit:true,			//edit
			reloadAfterSubmit : true,
			checkOnSubmit:true,
			beforeSubmit:validateForm
		},{									//add
			width:600,
			modal:true,
			closeAfterAdd:true,
			reloadAfterSubmit : true,
			beforeSubmit:validateForm
		},{									//del
			left:300
		},{								    //search
			closeAfterSearch:true,
			reloadAfterSubmit : true,
			multipleSearch:true
		});
	});
	
	//对表单进行验证
	function validateForm(postdata, formid){
		//设置id
		postdata['id'] = "";
		return [true, '保存成功'];
	}	
	
	
	//初始化控件
	$(document).ready(function(){
		$(".buttons").button();
		$('.buttons').click(function(){
			var result=$(this).val();
			jConfirm('确认审核吗?', '',function(r){
				if(r){
					confirm(result);
				}
			});
		});
	});
	
	var state='to_apply';
	function confirm(result){
		var ids=jQuery("#list").jqGrid('getGridParam','selarrrow');
		var data="ids="+ids;
		data+="&result="+result;
		data+='&state='+state;
		$.ajax({
			url:'${ctx}/admin/confirmMoney/confirm',
			data:data,
			success:function(result){
				if(result=='success'){
					jAlert('全部审核成功');
					jQuery("#list").jqGrid('setGridParam',{url:"${ctx}/admin/confirmMoney/outList?state=to_apply",page:1}).trigger("reloadGrid");
				}else if(result=='part'){
					jAlert('部分审核成功');
				}else{
					jAlert('操作失败,请重试');
				}
			}
		});
	}
	
</script>
</head>
<body>
	<div style="margin-left:100px;margin-top:20px;">
		<input type="button" class="buttons" id='pass' value="PASS"/>
		<input type="button" class="buttons" id='not' value="NOT"/>
	</div>
	<div style="margin-left:100px;">
		<table id="list"></table>
		<div id="pager"></div>
	</div>
</body>
</html>